import http from '../utils/http';

/**
 * 获取列表
 */
function getCodeMap(){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtCodeMapping/find').then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function getReadXlsConfig(){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcelConfig/find').then(res => {
            resolve (res);
            return;
        },error => {
            console.log("getReadXlsConfig!~",error);
            reject(error)
        })
    })
}



function saveReadXlsConfig(config){
    return new Promise((resolve, reject) => {
        http("post",'/dt/dtReadExcelConfig/saveAll',config).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function  getFileInfo(fileName){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcel/find',{"fileName":fileName}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function  getFileInfos(){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcel/find').then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function  importAccAndDpt(){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtVoucherDetail/importAccAndDpt').then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function  getVoucherInfos(execelId){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtVoucher/find',{"excelId":execelId}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}



function  getXlsData(fileId){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcelData/find',{"refId":fileId}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}

//删除已经读入的excel数据
function  removeById(id){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcel/removeById',{"id":id}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}

//生成凭证
function  toVch(id,maker,dcCode,dc,vchDate,setId){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcel/toVch',{"id":id,"maker":maker, "dcCode":dcCode, "dc":dc, "vchDate":vchDate,"setId":setId}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}

//写入财务系统 R pushVch(String id, Date vchDate,Integer setId)
function  toAccountSys(id,vchDate,setId){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtReadExcel/pushVch',{"id":id, "vchDate":vchDate,"setId":setId}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


//会计分录
function  getAccountingEntry(vouId){
    return new Promise((resolve, reject) => {
        http("get",'/dt/dtVoucherDetail/find',{"vouId":vouId}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}



//executeSql
function  executeSql(sql){
    return new Promise((resolve, reject) => {
        http("get",'/metadata/other/executeSql',{"sql":sql}).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


export {
    getCodeMap,getReadXlsConfig,saveReadXlsConfig,getFileInfo,getFileInfos,importAccAndDpt,
    getXlsData,removeById,toVch,getVoucherInfos,getAccountingEntry,toAccountSys,
    executeSql
}

